import Screen from './Screen.js'

export type ComponentOptions = {
  x?: number
  y?: number
  width?: number
  height?: number
}

export interface ComponentInterface {
  parent?: ComponentInterface
  options: ComponentOptions
  screen?: Screen;

  // -----> 组件属性 START <-----
  x: number
  y: number
  width: number
  height: number
  // -----> 组件属性 END <-----

  // -----> 父级控制逻辑 START <----- 
  screenX?: number
  screenY?: number
  // -----> 父级控制逻辑 END <----- 

  init() : Promise<void>
  
  load() : Promise<void>
  unload() : Promise<void>

  destroy() : Promise<void>
  update(dt: number): Promise<void>
  resize(): Promise<void>
}

export default class Component implements ComponentInterface {
  x: number
  y: number
  width: number
  height: number
  screenX: number
  screenY: number
  screen?: Screen
  options: ComponentOptions
  parent?: ComponentInterface

  constructor(options: ComponentOptions = {}) {
    this.options = options
    this.x = options.x ?? 0
    this.y = options.y ?? 0
    this.width = options.width ?? 0
    this.height = options.height ?? 0
    this.screenX = 0
    this.screenY = 0
  }
  
  async init(): Promise<void> {
    
  }
  async load(): Promise<void> {
    
  }
  async unload(): Promise<void> {
    
  }
  async destroy(): Promise<void> {
    
  }
  async update(dt: number): Promise<void> {
    
  }

  async resize(): Promise<void> {

  }
}